//
//  ZZCBaseViewController.m
//  B段项目
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCBaseViewController.h"

@interface ZZCBaseViewController ()

@end

@implementation ZZCBaseViewController

#pragma mark -ViewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];
    //自定义左侧调出抽屉按钮
    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftButton.frame = CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.height, self.navigationController.navigationBar.frame.size.height);
    
    //因为图片太大 所以在button上加一个小的UIImageView
    self.leftImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.leftButton.frame.size.width / 4, self.leftButton.frame.size.width / 4, self.leftButton.frame.size.width / 2, self.leftButton.frame.size.width / 2)];
    self.leftImage.image = [UIImage imageNamed:@"iconfont-daohangliebiao-3.png"];
    [self.leftButton addSubview:self.leftImage];
    
    self.leftButton.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.leftButton];
    [self.leftButton addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //创建一个空View顶替系统LeftBar
    UIView *nilView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:nilView];
    
    //自定义右边View
    self.rightView = [[UIView alloc]initWithFrame:CGRectMake(self.leftButton.frame.size.width + 1, 0, self.navigationController.navigationBar.frame.size.width - self.leftButton.frame.size.width - 1, self.navigationController.navigationBar.frame.size.height)];
    self.rightView.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.rightView];
    
    //创建label(navigationItem.title)来显示每页标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.rightView.height / 4, self.rightView.height / 4, self.navigationController.navigationBar.frame.size.width / 3, self.rightView.height / 2)];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.rightView addSubview:self.titleLabel];
    
    self.navigationController.navigationBar.translucent = NO;
    
}

#pragma mark - 左按钮
- (void)leftAction:(UIButton *)leftAction{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    if (app.leftSliderVC.closed)
    {
        [app.leftSliderVC openLeftView];
    }
    else
    {
        [app.leftSliderVC closeLeftView];
    }
    
    
}





#pragma mark - 页面快消失的时候

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //    NSLog(@"viewWillDisappear");
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.leftSliderVC setPanEnabled:NO];
}


#pragma mark - 页面快出现的时候

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //    NSLog(@"viewWillAppear");
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.leftSliderVC setPanEnabled:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
